﻿using System;
using System.Data;
using System.Windows.Forms;
namespace ceTerm
{
    public class Settings
    {
        public static class Power
        {
            public static int Yazma = -1;
            public static int OkumaMin = -1;
            public static int OkumaMax = -1;
        }

        public static string WebServiceURL = string.Empty;
        public static string MessengerURL = string.Empty;

        public static int TerminalId = -1;
        public static int OkumaSuresiMs = 100;

        public static bool IsInDebugMode = false;

        public static void Init()
        {
            try
            {
                string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
                string xmlFileUrl = new System.IO.FileInfo(path).DirectoryName + @"\Settings.txt";

                DataSet ds = new DataSet("ceTerm");
                ds.ReadXml(xmlFileUrl);
                DataRow dr = ds.Tables[0].Rows[0];

                Power.Yazma = XForm.intParse(dr["Yazma"].ToString());
                Power.OkumaMin = Main.intParse(dr["OkumaMin"].ToString());
                Power.OkumaMax = Main.intParse(dr["OkumaMax"].ToString());                
                OkumaSuresiMs = Main.intParse(dr["OkumaSuresiMs"].ToString());
                WebServiceURL = dr["WebServiceURL"].ToString();
                MessengerURL = dr["MessengerURL"].ToString();

                IsInDebugMode = false;
                
                if (IsInDebugMode)
                {
                    WebServiceURL = "http://confexpert.karbel.com/ceTerminal/ceTerminal.asmx";                    
                }
            }
            catch(Exception Ex)
            {
                MessageBox.Show("Settings.txt okunamadı!" + Ex.ToString(), "Error");
            }
        }
    }
}